package cn.dnui_zjs008.dnuifood_madp003.model;

import cn.dnui_zjs008.dnuifood_madp003.bean.ResultBean;
import cn.dnui_zjs008.dnuifood_madp003.bean.UserBean;
import cn.dnui_zjs008.dnuifood_madp003.iface.UserIface;
import cn.dnui_zjs008.dnuifood_madp003.listener.onRetrofitListener;
import cn.dnui_zjs008.dnuifood_madp003.service.UserService;
import retrofit2.Call;

public class UserModel extends BaseModel implements UserIface {
    private UserService service;
    @Override
    public void login(String username, String userpass,
                      final onRetrofitListener listener) {
        service =retrofit.create(UserService.class);
        Call<UserBean> call=service
                .doLogin(username,userpass);
        bindCallback(call,listener,1);
        /*call.enqueue(new Callback<UserBean>() {
            @Override
            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
                if(response.body()!=null)
                    listener.onSuccess(response.body());
                else
                    listener.onFalure("解析错误！");
            }

            @Override
            public void onFailure(Call<UserBean> call, Throwable t) {
                listener.onFalure(t.toString());
            }
        });*/

    }

    @Override
    public void register(String username, String userpass, String mobilenum, String address, String comment, onRetrofitListener listener) {
        service = retrofit.create(UserService.class);
        Call<ResultBean> call;
        call = service.doRegist(username,userpass,
                mobilenum,address,comment);
        bindCallback(call,listener,1);
    }
}
